<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - ged.info - gil/image_view.hpp</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LTP GCOV extension - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
        <tr>
          <td class="headerItem" width="20%">Current&nbsp;view:</td>
          <td class="headerValue" width="80%" colspan=4><a href="../index.html">directory</a> - <a href="index.html">gil</a> - image_view.hpp</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Test:</td>
          <td class="headerValue" width="80%" colspan=4>ged.info</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Date:</td>
          <td class="headerValue" width="20%">2009-06-09</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Instrumented&nbsp;lines:</td>
          <td class="headerValue" width="20%">23</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Code&nbsp;covered:</td>
          <td class="headerValue" width="20%">91.3 %</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Executed&nbsp;lines:</td>
          <td class="headerValue" width="20%">21</td>
        </tr>
        </table>
      </td>
    </tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td><pre class="source">
<span class="lineNum">       1 </span>                : /*
<span class="lineNum">       2 </span>                :     Copyright 2005-2007 Adobe Systems Incorporated
<span class="lineNum">       3 </span>                :    
<span class="lineNum">       4 </span>                :     Use, modification and distribution are subject to the Boost Software License,
<span class="lineNum">       5 </span>                :     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
<span class="lineNum">       6 </span>                :     http://www.boost.org/LICENSE_1_0.txt).
<span class="lineNum">       7 </span>                : 
<span class="lineNum">       8 </span>                :     See http://opensource.adobe.com/gil for most recent version including documentation.
<span class="lineNum">       9 </span>                : */
<span class="lineNum">      10 </span>                : /*************************************************************************************************/
<span class="lineNum">      11 </span>                : 
<span class="lineNum">      12 </span>                : #ifndef GIL_IMAGE_VIEW_H
<span class="lineNum">      13 </span>                : #define GIL_IMAGE_VIEW_H
<span class="lineNum">      14 </span>                : 
<span class="lineNum">      15 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      16 </span>                : /// \file               
<span class="lineNum">      17 </span>                : /// \brief image view class
<span class="lineNum">      18 </span>                : /// \author Lubomir Bourdev and Hailin Jin \n
<span class="lineNum">      19 </span>                : ///         Adobe Systems Incorporated
<span class="lineNum">      20 </span>                : /// \date 2005-2007 \n Last updated on February 12, 2007
<span class="lineNum">      21 </span>                : ///
<span class="lineNum">      22 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      23 </span>                : 
<span class="lineNum">      24 </span>                : #include &lt;cstddef&gt;
<span class="lineNum">      25 </span>                : #include &lt;iterator&gt;
<span class="lineNum">      26 </span>                : #include &quot;gil_config.hpp&quot;
<span class="lineNum">      27 </span>                : #include &quot;iterator_from_2d.hpp&quot;
<span class="lineNum">      28 </span>                : 
<span class="lineNum">      29 </span>                : //#ifdef _MSC_VER
<span class="lineNum">      30 </span>                : //#pragma warning(push)
<span class="lineNum">      31 </span>                : //#pragma warning(disable : 4244)     // conversion from 'gil::image&lt;V,Alloc&gt;::coord_t' to 'int', possible loss of data (visual studio compiler doesn't realize that the two types are the same)
<span class="lineNum">      32 </span>                : //#endif
<span class="lineNum">      33 </span>                : 
<span class="lineNum">      34 </span>                : namespace boost { namespace gil {
<span class="lineNum">      35 </span>                : 
<span class="lineNum">      36 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      37 </span>                : /// \class image_view
<span class="lineNum">      38 </span>                : /// \ingroup ImageViewModel PixelBasedModel
<span class="lineNum">      39 </span>                : /// \brief A lightweight object that interprets memory as a 2D array of pixels. Models ImageViewConcept,PixelBasedConcept,HasDynamicXStepTypeConcept,HasDynamicYStepTypeConcept,HasTransposedTypeConcept
<span class="lineNum">      40 </span>                : ///
<span class="lineNum">      41 </span>                : /// Image view consists of a pixel 2D locator (defining the mechanism for navigating in 2D)
<span class="lineNum">      42 </span>                : /// and the image dimensions.
<span class="lineNum">      43 </span>                : ///
<span class="lineNum">      44 </span>                : /// Image views to images are what ranges are to STL containers. They are lightweight objects,
<span class="lineNum">      45 </span>                : /// that don't own the pixels. It is the user's responsibility that the underlying data remains
<span class="lineNum">      46 </span>                : /// valid for the lifetime of the image view.
<span class="lineNum">      47 </span>                : ///
<span class="lineNum">      48 </span>                : /// Similar to iterators and ranges, constness of views does not extend to constness of pixels. 
<span class="lineNum">      49 </span>                : /// A const \p image_view does not allow changing its location in memory (resizing, moving) but does 
<span class="lineNum">      50 </span>                : /// not prevent one from changing the pixels. The latter requires an image view whose value_type
<span class="lineNum">      51 </span>                : /// is const.
<span class="lineNum">      52 </span>                : ///
<span class="lineNum">      53 </span>                : /// Images have interfaces consistent with STL 1D random access containers, so they can be used
<span class="lineNum">      54 </span>                : /// directly in STL algorithms like:
<span class="lineNum">      55 </span>                : /// \code
<span class="lineNum">      56 </span>                : ///  std::fill(img.begin(), img.end(), red_pixel);
<span class="lineNum">      57 </span>                : /// \endcode
<span class="lineNum">      58 </span>                : ///
<span class="lineNum">      59 </span>                : /// In addition, horizontal, vertical and 2D random access iterators are provided.
<span class="lineNum">      60 </span>                : ///
<span class="lineNum">      61 </span>                : /// Note also that \p image_view does not require that its element type be a pixel. It could be
<span class="lineNum">      62 </span>                : /// instantiated with a locator whose \p value_type models only \p Regular. In this case the image
<span class="lineNum">      63 </span>                : /// view models the weaker RandomAccess2DImageViewConcept, and does not model PixelBasedConcept.
<span class="lineNum">      64 </span>                : /// Many generic algorithms don't require the elements to be pixels.
<span class="lineNum">      65 </span>                : ///
<span class="lineNum">      66 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      67 </span>                : template &lt;typename Loc&gt;     // Models 2D Pixel Locator
<span class="lineNum">      68 </span><span class="lineCov">            231 : class image_view {</span>
<span class="lineNum">      69 </span>                : public:
<span class="lineNum">      70 </span>                : 
<span class="lineNum">      71 </span>                : // typedefs required by ConstRandomAccessNDImageViewConcept
<span class="lineNum">      72 </span>                :     static const std::size_t num_dimensions=2;
<span class="lineNum">      73 </span>                :     typedef typename Loc::value_type                 value_type;
<span class="lineNum">      74 </span>                :     typedef typename Loc::reference                  reference;       // result of dereferencing
<span class="lineNum">      75 </span>                :     typedef typename Loc::coord_t                    coord_t;      // 1D difference type (same for all dimensions)
<span class="lineNum">      76 </span>                :     typedef coord_t                                  difference_type; // result of operator-(1d_iterator,1d_iterator)
<span class="lineNum">      77 </span>                :     typedef typename Loc::point_t                    point_t;
<span class="lineNum">      78 </span>                :     typedef Loc                                      locator;
<span class="lineNum">      79 </span>                :     typedef image_view&lt;typename Loc::const_t&gt;        const_t;      // same as this type, but over const values
<span class="lineNum">      80 </span>                :     template &lt;std::size_t D&gt; struct axis {
<span class="lineNum">      81 </span>                :         typedef typename Loc::template axis&lt;D&gt;::coord_t  coord_t;     // difference_type along each dimension
<span class="lineNum">      82 </span>                :         typedef typename Loc::template axis&lt;D&gt;::iterator iterator;       // 1D iterator type along each dimension
<span class="lineNum">      83 </span>                :     };
<span class="lineNum">      84 </span>                :     typedef iterator_from_2d&lt;Loc&gt;                    iterator;       // 1D iterator type for each pixel left-to-right inside top-to-bottom
<span class="lineNum">      85 </span>                :     typedef std::reverse_iterator&lt;iterator&gt;          reverse_iterator;
<span class="lineNum">      86 </span>                :     typedef std::size_t                              size_type;
<span class="lineNum">      87 </span>                : 
<span class="lineNum">      88 </span>                : // typedefs required by ConstRandomAccess2DImageViewConcept
<span class="lineNum">      89 </span>                :     typedef locator                                  xy_locator;
<span class="lineNum">      90 </span>                :     typedef typename xy_locator::x_iterator          x_iterator;     // pixel iterator along a row
<span class="lineNum">      91 </span>                :     typedef typename xy_locator::y_iterator          y_iterator;     // pixel iterator along a column
<span class="lineNum">      92 </span>                :     typedef typename xy_locator::x_coord_t           x_coord_t;
<span class="lineNum">      93 </span>                :     typedef typename xy_locator::y_coord_t           y_coord_t;
<span class="lineNum">      94 </span>                : 
<span class="lineNum">      95 </span>                :     template &lt;typename Deref&gt; struct add_deref {
<span class="lineNum">      96 </span>                :         typedef image_view&lt;typename Loc::template add_deref&lt;Deref&gt;::type&gt; type;
<span class="lineNum">      97 </span>                :         static type make(const image_view&lt;Loc&gt;&amp; iv, const Deref&amp; d) { return type(iv.dimensions(), Loc::template add_deref&lt;Deref&gt;::make(iv.pixels(),d)); }
<span class="lineNum">      98 </span>                :     };
<span class="lineNum">      99 </span>                : 
<span class="lineNum">     100 </span><span class="lineCov">             49 :     image_view() : _dimensions(0,0) {}</span>
<span class="lineNum">     101 </span>                :     template &lt;typename View&gt; image_view(const View&amp; iv)                                    : _dimensions(iv.dimensions()), _pixels(iv.pixels()) {}
<span class="lineNum">     102 </span>                : 
<span class="lineNum">     103 </span><span class="lineCov">             35 :     template &lt;typename L2&gt; image_view(const point_t&amp; sz            , const L2&amp; loc)        : _dimensions(sz),          _pixels(loc) {}</span>
<span class="lineNum">     104 </span><span class="lineCov">             14 :     template &lt;typename L2&gt; image_view(coord_t width, coord_t height, const L2&amp; loc)        : _dimensions(x_coord_t(width),y_coord_t(height)), _pixels(loc) {}</span>
<span class="lineNum">     105 </span>                : 
<span class="lineNum">     106 </span>                :     template &lt;typename View&gt; image_view&amp; operator=(const View&amp; iv)  { _pixels=iv.pixels(); _dimensions=iv.dimensions(); return *this; }
<span class="lineNum">     107 </span><span class="lineCov">             88 :     image_view&amp; operator=(const image_view&amp; iv)                     { _pixels=iv.pixels(); _dimensions=iv.dimensions(); return *this; }</span>
<span class="lineNum">     108 </span>                : 
<span class="lineNum">     109 </span><span class="lineCov">             12 :     template &lt;typename View&gt; bool operator==(const View&amp; v) const   { return pixels()==v.pixels() &amp;&amp; dimensions()==v.dimensions(); }</span>
<span class="lineNum">     110 </span>                :     template &lt;typename View&gt; bool operator!=(const View&amp; v) const   { return !(*this==v); }
<span class="lineNum">     111 </span>                : 
<span class="lineNum">     112 </span>                :     template &lt;typename L2&gt; friend void swap(image_view&lt;L2&gt;&amp; x, image_view&lt;L2&gt;&amp; y);
<span class="lineNum">     113 </span>                : 
<span class="lineNum">     114 </span><span class="lineCov">            736 :     const point_t&amp;   dimensions()            const { return _dimensions; }</span>
<span class="lineNum">     115 </span><span class="lineCov">             75 :     const locator&amp;   pixels()                const { return _pixels; }</span>
<span class="lineNum">     116 </span><span class="lineCov">             49 :     x_coord_t        width()                 const { return dimensions().x; }</span>
<span class="lineNum">     117 </span><span class="lineCov">            559 :     y_coord_t        height()                const { return dimensions().y; }</span>
<span class="lineNum">     118 </span>                :     std::size_t      num_channels()          const { return gil::num_channels&lt;value_type&gt;::value; }
<span class="lineNum">     119 </span><span class="lineCov">             15 :     bool             is_1d_traversable()     const { return _pixels.is_1d_traversable(width()); }</span>
<span class="lineNum">     120 </span>                : 
<span class="lineNum">     121 </span>                :     //\{@
<span class="lineNum">     122 </span>                :     /// \name 1D navigation
<span class="lineNum">     123 </span><span class="lineCov">              7 :     size_type           size()               const { return width()*height(); }  </span>
<span class="lineNum">     124 </span><span class="lineCov">             14 :     iterator            begin()              const { return iterator(_pixels,_dimensions.x); }</span>
<span class="lineNum">     125 </span><span class="lineCov">              7 :     iterator            end()                const { return begin()+(difference_type)size(); }    // potential performance problem!</span>
<span class="lineNum">     126 </span>                :     reverse_iterator    rbegin()             const { return reverse_iterator(end()); }
<span class="lineNum">     127 </span>                :     reverse_iterator    rend()               const { return reverse_iterator(begin()); }
<span class="lineNum">     128 </span>                :     reference operator[](difference_type i)  const { return begin()[i]; }        // potential performance problem!
<span class="lineNum">     129 </span>                :     iterator            at(difference_type i)const { return begin()+i; }
<span class="lineNum">     130 </span>                :     iterator            at(const point_t&amp; p) const { return begin()+p.y*width()+p.x; }
<span class="lineNum">     131 </span>                :     iterator            at(x_coord_t x, y_coord_t y)const { return begin()+y*width()+x; }
<span class="lineNum">     132 </span>                : 
<span class="lineNum">     133 </span>                :     //\}@
<span class="lineNum">     134 </span>                : 
<span class="lineNum">     135 </span>                :     //\{@
<span class="lineNum">     136 </span>                :     /// \name 2-D navigation
<span class="lineNum">     137 </span><span class="lineNoCov">              0 :     reference operator()(const point_t&amp; p)        const { return _pixels(p.x,p.y); }</span>
<span class="lineNum">     138 </span>                :     reference operator()(x_coord_t x, y_coord_t y)const { return _pixels(x,y); }
<span class="lineNum">     139 </span>                :     template &lt;std::size_t D&gt; typename axis&lt;D&gt;::iterator axis_iterator(const point_t&amp; p) const { return _pixels.axis_iterator&lt;D&gt;(p); }
<span class="lineNum">     140 </span><span class="lineCov">             52 :     xy_locator xy_at(x_coord_t x, y_coord_t y)    const { return _pixels+point_t(x_coord_t(x),y_coord_t(y)); }</span>
<span class="lineNum">     141 </span>                :     locator    xy_at(const point_t&amp; p)            const { return _pixels+p; }
<span class="lineNum">     142 </span>                :     //\}@
<span class="lineNum">     143 </span>                : 
<span class="lineNum">     144 </span>                :     //\{@
<span class="lineNum">     145 </span>                :     /// \name X navigation
<span class="lineNum">     146 </span><span class="lineCov">            516 :     x_iterator x_at(x_coord_t x, y_coord_t y)     const { return _pixels.x_at(x,y); }</span>
<span class="lineNum">     147 </span>                :     x_iterator x_at(const point_t&amp; p)             const { return _pixels.x_at(p); }
<span class="lineNum">     148 </span><span class="lineCov">            516 :     x_iterator row_begin(y_coord_t y)             const { return x_at(0,y); }</span>
<span class="lineNum">     149 </span><span class="lineNoCov">              0 :     x_iterator row_end(y_coord_t y)               const { return x_at(width(),y); }</span>
<span class="lineNum">     150 </span>                :     //\}@
<span class="lineNum">     151 </span>                : 
<span class="lineNum">     152 </span>                :     //\{@
<span class="lineNum">     153 </span>                :     /// \name Y navigation
<span class="lineNum">     154 </span>                :     y_iterator y_at(x_coord_t x, y_coord_t y)     const { return xy_at(x,y).y(); }
<span class="lineNum">     155 </span>                :     y_iterator y_at(const point_t&amp; p)             const { return xy_at(p).y(); }
<span class="lineNum">     156 </span>                :     y_iterator col_begin(x_coord_t x)             const { return y_at(x,0); }
<span class="lineNum">     157 </span>                :     y_iterator col_end(x_coord_t x)               const { return y_at(x,height()); }
<span class="lineNum">     158 </span>                :     //\}@
<span class="lineNum">     159 </span>                : 
<span class="lineNum">     160 </span>                : private:
<span class="lineNum">     161 </span>                :     template &lt;typename L2&gt; friend class image_view;
<span class="lineNum">     162 </span>                : 
<span class="lineNum">     163 </span>                :     point_t    _dimensions;
<span class="lineNum">     164 </span>                :     xy_locator _pixels;
<span class="lineNum">     165 </span>                : };
<span class="lineNum">     166 </span>                : 
<span class="lineNum">     167 </span>                : template &lt;typename L2&gt; 
<span class="lineNum">     168 </span><span class="lineCov">              6 : inline void swap(image_view&lt;L2&gt;&amp; x, image_view&lt;L2&gt;&amp; y) { </span>
<span class="lineNum">     169 </span>                :     using std::swap;
<span class="lineNum">     170 </span><span class="lineCov">              6 :     swap(x._dimensions,y._dimensions); </span>
<span class="lineNum">     171 </span><span class="lineCov">              6 :     swap(x._pixels, y._pixels);            // TODO: Extend further</span>
<span class="lineNum">     172 </span><span class="lineCov">              6 : }</span>
<span class="lineNum">     173 </span>                : 
<span class="lineNum">     174 </span>                : /////////////////////////////
<span class="lineNum">     175 </span>                : //  PixelBasedConcept
<span class="lineNum">     176 </span>                : /////////////////////////////
<span class="lineNum">     177 </span>                : 
<span class="lineNum">     178 </span>                : template &lt;typename L&gt;
<span class="lineNum">     179 </span>                : struct channel_type&lt;image_view&lt;L&gt; &gt; : public channel_type&lt;L&gt; {}; 
<span class="lineNum">     180 </span>                : 
<span class="lineNum">     181 </span>                : template &lt;typename L&gt;
<span class="lineNum">     182 </span>                : struct color_space_type&lt;image_view&lt;L&gt; &gt; : public color_space_type&lt;L&gt; {}; 
<span class="lineNum">     183 </span>                : 
<span class="lineNum">     184 </span>                : template &lt;typename L&gt;
<span class="lineNum">     185 </span>                : struct channel_mapping_type&lt;image_view&lt;L&gt; &gt; : public channel_mapping_type&lt;L&gt; {}; 
<span class="lineNum">     186 </span>                : 
<span class="lineNum">     187 </span>                : template &lt;typename L&gt;
<span class="lineNum">     188 </span>                : struct is_planar&lt;image_view&lt;L&gt; &gt; : public is_planar&lt;L&gt; {}; 
<span class="lineNum">     189 </span>                : 
<span class="lineNum">     190 </span>                : /////////////////////////////
<span class="lineNum">     191 </span>                : //  HasDynamicXStepTypeConcept
<span class="lineNum">     192 </span>                : /////////////////////////////
<span class="lineNum">     193 </span>                : 
<span class="lineNum">     194 </span>                : template &lt;typename L&gt;
<span class="lineNum">     195 </span>                : struct dynamic_x_step_type&lt;image_view&lt;L&gt; &gt; {
<span class="lineNum">     196 </span>                :     typedef image_view&lt;typename dynamic_x_step_type&lt;L&gt;::type&gt; type;
<span class="lineNum">     197 </span>                : };
<span class="lineNum">     198 </span>                : 
<span class="lineNum">     199 </span>                : /////////////////////////////
<span class="lineNum">     200 </span>                : //  HasDynamicYStepTypeConcept
<span class="lineNum">     201 </span>                : /////////////////////////////
<span class="lineNum">     202 </span>                : 
<span class="lineNum">     203 </span>                : template &lt;typename L&gt;
<span class="lineNum">     204 </span>                : struct dynamic_y_step_type&lt;image_view&lt;L&gt; &gt; {
<span class="lineNum">     205 </span>                :     typedef image_view&lt;typename dynamic_y_step_type&lt;L&gt;::type&gt; type;
<span class="lineNum">     206 </span>                : };
<span class="lineNum">     207 </span>                : 
<span class="lineNum">     208 </span>                : /////////////////////////////
<span class="lineNum">     209 </span>                : //  HasTransposedTypeConcept
<span class="lineNum">     210 </span>                : /////////////////////////////
<span class="lineNum">     211 </span>                : 
<span class="lineNum">     212 </span>                : template &lt;typename L&gt;
<span class="lineNum">     213 </span>                : struct transposed_type&lt;image_view&lt;L&gt; &gt; {
<span class="lineNum">     214 </span>                :     typedef image_view&lt;typename transposed_type&lt;L&gt;::type&gt; type;
<span class="lineNum">     215 </span>                : };
<span class="lineNum">     216 </span>                : 
<span class="lineNum">     217 </span>                : } }  // namespace boost::gil
<span class="lineNum">     218 </span>                : 
<span class="lineNum">     219 </span>                : //#ifdef _MSC_VER
<span class="lineNum">     220 </span>                : //#pragma warning(pop)
<span class="lineNum">     221 </span>                : //#endif
<span class="lineNum">     222 </span>                : 
<span class="lineNum">     223 </span>                : #endif
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
  <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LTP GCOV extension version 1.6</a></td></tr>
  </table>
  <br>

</body>
</html>
